package com.topisv.tms.service.work;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.AreaGroup;
import com.topisv.tms.entity.Customers;
import com.topisv.tms.entity.EdiGoodsSku;
import com.topisv.tms.entity.dto.OutstorageInfoDto;
import com.topisv.tms.entity.stock.oustorage.OutstorageBoxItem;
import com.topisv.tms.entity.work.ViewWorkOrder;
import com.topisv.tms.mybatis.Pagination;
import com.topisv.tms.mybatis.service.CommonService;
import com.topisv.tms.repository.AreaGroupDao;
import com.topisv.tms.repository.CustomersDao;
import com.topisv.tms.repository.EdiGoodsSkuDao;
import com.topisv.tms.repository.stock.outstorage.OutstorageBoxItemDao;
import com.topisv.tms.repository.work.ViewWorkOrderDao;
import com.topisv.tms.service.vo.QueryOutstorageInfoVO;

/**
 * 作业订单视图_service
 * 
 * @author ch
 * 
 */
@Component
@Transactional(readOnly = true)
public class ViewWorkOrderService extends CommonService{
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private ViewWorkOrderDao viewWorkOrderDao;
	@Autowired
	private EdiGoodsSkuDao ediGoodsSkuDao;
	@Autowired
	private CustomersDao customersDao;
	@Autowired
	private AreaGroupDao areaGroupDao;
	
	@Autowired
	private OutstorageBoxItemDao outstorageBoxItemDao;
	@PersistenceContext
    private EntityManager em;
	
	
	/**
	 * 出库信息dto查询
	 * @param param
	 * @return
	 */ 
	@Deprecated
	public List<OutstorageInfoDto> loadDtoByParam(Map<String, Object> param) {
		
		String customerCode=(String) param.get("customerCode");
		Customers customer=this.customersDao.findByCustomerCode(customerCode);
		String warehouseCode=(String) param.get("warehouseCode");
		AreaGroup warehouse=this.areaGroupDao.findByGroupCode(warehouseCode);
		
		
		//查询所有出库订单
		
		List<OutstorageInfoDto> dtoList=new ArrayList<OutstorageInfoDto>();
		List<ViewWorkOrder> infoList=this.loadByParam(param);
		
		//区分出库类型
		Map<String, Integer> map=new HashMap<String, Integer>();
		Map<String, Integer> map_normalOrder=new HashMap<String, Integer>();
		Map<String, Integer> map_ulOrder=new HashMap<String, Integer>();
		Map<String, Integer> map_recallOrder=new HashMap<String, Integer>();
		Map<String, Integer> map_exceptionOrder=new HashMap<String, Integer>();
		Map<String, Integer> map_allot=new HashMap<String, Integer>();
		Map<String, Integer> map_sale=new HashMap<String, Integer>();
		Map<String, Integer> map_return=new HashMap<String, Integer>();
		String orderno;
		String cancelStatus;
		String sku;
		Integer num;
		
		for(ViewWorkOrder vOrder:infoList){
			
			if(vOrder==null){
				continue;
			}
			
			 orderno=vOrder.getOrderno();
			 cancelStatus=vOrder.getCancelStatus();
			 sku=vOrder.getSku();
			 num=vOrder.getNum();
			 
			 if(orderno.endsWith("UL")){ //线下单
				 
				 if(map_ulOrder.keySet().contains(sku)){
					 map_ulOrder.put(sku,map_ulOrder.get(sku)+num);
				 }else{
					 map_ulOrder.put(sku, num);
				 }
					
			 }else if(orderno.endsWith("R")){ //重发单
				 
				 if(map_recallOrder.keySet().contains(sku)){
					 map_recallOrder.put(sku,map_recallOrder.get(sku)+num);
				 }else{
					 map_recallOrder.put(sku, num);
				 }
				 
			 }else if(!"ok".equals(cancelStatus)){ //异常单
				 
				 if(map_exceptionOrder.keySet().contains(sku)){
					 map_exceptionOrder.put(sku,map_exceptionOrder.get(sku)+num);
				 }else{
					 map_exceptionOrder.put(sku, num);
				 }
				 
			 }else{//正常单
				 
				 if(map_normalOrder.keySet().contains(sku)){
					 map_normalOrder.put(sku,map_normalOrder.get(sku)+num);
				 }else{
					 map_normalOrder.put(sku, num);
				 }
				 
			 }
			 
			 if(map.keySet().contains(sku)){
				 map.put(sku,map.get(sku)+num);
			 }else{
				 map.put(sku, num);
			 }
		}
		Date fromDate =(Date) param.get("fromDate");
		Date toDate =(Date) param.get("toDate");
		String sku2 =(String) param.get("sku");
		String shopCode=(String)param.get("shopCode");
		if(isBlank(shopCode)){
			List<OutstorageBoxItem> list = outstorageBoxItemDao.listByBill(isBlank(warehouseCode)?null:warehouseCode, isBlank(customerCode)?null:customerCode, null, fromDate, toDate,isBlank(sku2)?null:sku2);
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			logger.info("box size:"+list.size() +" warehouseCode = " +warehouseCode+" customerCode = "+customerCode +" fromDate = "+df.format(fromDate) +" toDate = "+ df.format(toDate) );
			for(OutstorageBoxItem item:list){
				sku = item.getSku();
				num = item.getNum();
				Map<String, Integer> map2=null;
				if("allot".equalsIgnoreCase(item.getBill().getBillType())){
					map2 =map_allot;
					
				} else if("sale".equalsIgnoreCase(item.getBill().getBillType())){
					map2 =map_sale;
				} else if("return".equalsIgnoreCase(item.getBill().getBillType())||"bad_return".equalsIgnoreCase(item.getBill().getBillType())){
					map2 =map_return;
				}
				if(map2.keySet().contains(sku)){
					map2.put(sku,map2.get(sku)+num);
				 }else{
					 map2.put(sku, num);
				 }
				 if(map.keySet().contains(sku)){
					 map.put(sku,map.get(sku)+num);
				 }else{
					 map.put(sku, num);
				 }
			}
			//创建DTO
		    for(String _sku:map.keySet()){
		    	OutstorageInfoDto dto=new OutstorageInfoDto();
		    	dto.setCustomerCode(customerCode);
		    	dto.setCustomer(customer);
		    	dto.setWarehouseCode(warehouseCode);
		    	dto.setWarehouse(warehouse);
		    	dto.setSku(_sku);
		    	
		    	dto.setNormalNum(map_normalOrder.get(_sku));
		    	dto.setUlOrderNum(map_ulOrder.get(_sku));
		    	dto.setRecallNum(map_recallOrder.get(_sku));
		    	dto.setExceptionNum(map_exceptionOrder.get(_sku));
		    	dto.setNum(map.get(_sku));
		    	dto.setAllotNum(map_allot.get(_sku));
		    	dto.setSaleNum(map_sale.get(_sku));
		    	dto.setReturnNum(map_return.get(_sku));
		    	EdiGoodsSku egs=this.ediGoodsSkuDao.findByCustomerCodeAndSku(customerCode, _sku);
		    	if(egs!=null){
		    		dto.setGoodsName(egs.getSkuName());
		    	}
		    	dtoList.add(dto);
		    }
		}
		return dtoList;
	}
	
	protected boolean isBlank(String val){
		return null == val|| val.trim().length()==0;
	}
	
	/**
	 * 查找信息
	 * @param param 查询参数
	 * @return
	 */
	@Deprecated
	public List<ViewWorkOrder> loadByParam(Map<String, Object> param) {
		Specification<ViewWorkOrder> spec = getWhereClause(param);
		List<ViewWorkOrder> infoList = this.viewWorkOrderDao.findAll(spec);
		for (ViewWorkOrder v : infoList) {
			this.setDetail(v);
		}
		return infoList;
	}
	
	/**
	 * 设置属性
	 * @param v
	 */
	public void setDetail(ViewWorkOrder v) {
		try {
			
			if(v==null){
				return;
			}
			
			//商家
			Customers customer=this.customersDao.findByCustomerCode(v.getCustomerCode());
			v.setCustomer(customer);
			
			//仓库
			AreaGroup warehouse=this.areaGroupDao.findByGroupCode(v.getWarehouseCode());
			v.setWarehouse(warehouse);
			
		} catch (Exception e) {
			
		}
	}
	
	/**
	 * 查询条件封装
	 * @param param
	 * @return
	 */
	private Specification<ViewWorkOrder> getWhereClause(final Map<String, Object> param) {
		
		return new Specification<ViewWorkOrder>(){
			
		    @Override
		    public Predicate toPredicate(Root<ViewWorkOrder> r, CriteriaQuery<?> q, CriteriaBuilder cb) {
		      Predicate pre = cb.conjunction();
		      
		      String customerCode=(String) param.get("customerCode");
		      if(StringUtils.isNotBlank(customerCode)){
					pre.getExpressions().add(cb.equal(r.get("customerCode"),customerCode.trim()));
			  }
		      
		      String warehouseCode=(String) param.get("warehouseCode");
		      if(StringUtils.isNotBlank(warehouseCode)){
					pre.getExpressions().add(cb.equal(r.get("warehouseCode"),warehouseCode.trim()));
			  }

		      String sku=(String) param.get("sku");
		      if(StringUtils.isNotBlank(sku)){
					pre.getExpressions().add(cb.equal(r.get("sku"),sku));
			  }	
		      
		      String shopCode=(String) param.get("shopCode");
		      if(StringUtils.isNotBlank(shopCode)){
					pre.getExpressions().add(cb.equal(r.get("shopCode"),shopCode));
			  }	
		      
		      String batchCode=(String) param.get("batchCode");
		      if(StringUtils.isNotBlank(batchCode)){
					pre.getExpressions().add(cb.equal(r.get("batchCode"),batchCode));
			  }	
		      
		      String cancelStatus=(String) param.get("cancelStatus");
		      if(StringUtils.isNotBlank(cancelStatus)){
					pre.getExpressions().add(cb.equal(r.get("cancelStatus"),cancelStatus));
			  }	
		      
		      String taskCode=(String) param.get("taskCode");
		      if(StringUtils.isNotBlank(taskCode)){
					pre.getExpressions().add(cb.equal(r.get("taskCode"),taskCode));
			  }	
		      
		      Date fromDate= (Date) param.get("fromDate");
		      if (fromDate != null) {
		        pre.getExpressions().add(cb.greaterThanOrEqualTo(r.<Date>get("createTime"), fromDate));
		      }
		      
		      Date toDate= (Date) param.get("toDate");
		      if (toDate != null) {
		        pre.getExpressions().add(cb.lessThanOrEqualTo(r.<Date>get("createTime"), toDate));
		      }
		      
		      String status=(String) param.get("status");
		      if(StringUtils.isNotBlank(status)){
		    	  if(status.equals("countStock")){
		    		  pre.getExpressions().add(cb.greaterThan(r.<String>get("status"),"1"));  
		    	  }else{
		    		  pre.getExpressions().add(cb.equal(r.get("status"),status));  
		    	  }
			  }	
		      
		      return pre;
		    }
		  };
       }
	
	
	/**
	 * aim to insteadof loadDtoByParam(...)
	 * 
	 * @param param 查询参数
	 * @return 集合
	 */
    @SuppressWarnings("unchecked")
    public List<Object[]> loadDtoByParamNew(Map<String, Object> param) {
        String customerCode   = (String) param.get("customerCode");
        String warehouseCode = (String) param.get("warehouseCode");
        String sku                   = (String) param.get("sku");
        String shopCode         = (String) param.get("shopCode");
        String batchCode        = (String) param.get("batchCode");
        String cancelStatus      = (String) param.get("cancelStatus");
        String taskCode          = (String) param.get("taskCode");
        String fromDate          = (String) param.get("fromDate");
        String toDate              = (String) param.get("toDate");
        String status               = (String) param.get("status");
	    
	    
        //构建SQL
        StringBuffer sql = new StringBuffer("SELECT ");
        sql.append("   t1.customer_name 商家, ")
            .append("   t2.group_name 仓库, ")
            .append("   t.商品编码 SKU, ")
            .append("   t3.sku_name 商品名称,")
            .append("   SUM(t.正常单数量) 订单数, ")
            .append("   SUM(t.线下单数量) 线下单数, ")
            .append("   SUM(t.重发单数量) 重发单数, ")
            .append("   SUM(t.异常单数量) 异常单数, ")
            .append("   SUM(t.调拨数量) 调拨数, ")
            .append("   SUM(t.销售数量) 销售数, ")
            .append("   SUM(t.返厂数量) 返厂数, ")
            .append("   SUM(t.线下单数量 + t.重发单数量 + t.异常单数量 + t.正常单数量 + t.调拨数量 + t.销售数量 + t.返厂数量) 出库合计, ")
            .append("   t.客户编码, ")
            .append("   t.仓库编码 ")
            .append(" FROM ( ")
            .append("   SELECT ")
            .append("     t0.客户编码, ")
            .append("     t0.仓库编码, ")
            .append("     t0.商品编码, ")
            .append("     CASE t0.订单类别 WHEN '线下单' THEN t0.数量 ELSE 0 END 线下单数量, ")
            .append("     CASE t0.订单类别 WHEN '重发单' THEN t0.数量 ELSE 0 END 重发单数量, ")
            .append("     CASE t0.订单类别 WHEN '异常单' THEN t0.数量 ELSE 0 END 异常单数量, ")
            .append("     CASE t0.订单类别 WHEN '正常单' THEN t0.数量 ELSE 0 END 正常单数量, ")
            .append("     0 调拨数量, ")
            .append("     0 销售数量, ")
            .append("     0 返厂数量 ")
            .append("   FROM ( ")
            .append("     SELECT ")
            .append("       a0.customer_code 客户编码, ")
            .append("       a0.warehouse_code 仓库编码, ")
            .append("       CASE WHEN RIGHT(a0.orderno, 2)='UL' THEN '线下单' ")
            .append("       WHEN RIGHT(a0.orderno, 1)='R' THEN '重发单' ")
            .append("       WHEN a0.cancel_status <> 'ok' THEN '异常单' ")
            .append("       ELSE '正常单' END 订单类别, ")
            .append("       b0.sku_id 商品编码, ")
            .append("       b0.qty 数量 ")
            .append("     FROM work_order a0, edi_order_item b0 ");
            
        if (StringUtils.isNotBlank(shopCode)) sql.append(", edi_order c0 ");

        sql.append("       WHERE 1=1 ").append("       AND b0.ordeno = a0.orderno ");
        
        if (StringUtils.isNotBlank(shopCode))         sql.append("       AND c0.ordeno = a0.orderno ");
        if (StringUtils.isNotBlank(warehouseCode)) sql.append("       AND a0.warehouse_code= ? ");
        if (StringUtils.isNotBlank(customerCode))   sql.append("       AND a0.customer_code= ?");
        if (StringUtils.isNotBlank(sku))                   sql.append("       AND b0.sku_id = ?  ");
        if (StringUtils.isNotBlank(shopCode))         sql.append("       AND c0.shop_code = ? ");
        if (StringUtils.isNotBlank(batchCode))        sql.append("       AND a0.batch_code = ? ");
        if (StringUtils.isNotBlank(cancelStatus))      sql.append("       AND a0.cancel_status = ? ");
        if (StringUtils.isNotBlank(taskCode))          sql.append("       AND a0.task_code = ? ");
        if (StringUtils.isNotBlank(status)) {
            if ("countStock".equals(status)) {
                sql.append("       AND a0.status > ? ");
            } else {
                sql.append("       AND a0.status = ? ");
            }
        }
        if (StringUtils.isNotBlank(fromDate))          sql.append("       AND a0.create_time >= ? ");
        if (StringUtils.isNotBlank(toDate))              sql.append("       AND a0.create_time <= ? ");
        
        sql.append("   ) t0 ")
            .append("   UNION ALL ")
            .append("   SELECT ")
            .append("     b1.customer_code 客户编码, ")
            .append("     b1.warehouse_out_code 仓库编码, ")
            .append("     a1.sku 商品编码, ")
            .append("     0 线下单数量, ")
            .append("     0 重发单数量, ")
            .append("     0 异常单数量, ")
            .append("     0 正常单数量, ")
            .append("     CASE LOWER(b1.bill_type) WHEN 'allot' THEN a1.num ELSE 0 END 调拨数量, ")
            .append("     CASE LOWER(b1.bill_type) WHEN 'sale' THEN a1.num ELSE 0 END 销售数量, ")
            .append("     CASE LOWER(b1.bill_type) WHEN 'return' THEN a1.num ELSE 0 END 返厂数量 ")
            .append("   FROM outstorage_box_item a1 ")
            .append("   LEFT JOIN outstorage_bill b1 ON a1.bill_code=b1.bill_code ")
            .append("  ")
            .append("   WHERE 1=1 ")
            .append("   AND b1.status in ('5', '6') ");
        if (StringUtils.isNotBlank(sku))                    sql.append("      AND a1.sku = ? ");
        if (StringUtils.isNotBlank(customerCode))    sql.append("      AND b1.customer_code = ? ");
        if (StringUtils.isNotBlank(warehouseCode)) sql.append("       AND b1.warehouse_out_code = ? ");
        if (StringUtils.isNotBlank(fromDate))           sql.append("       AND b1.create_time >= ? ");
        if (StringUtils.isNotBlank(toDate))               sql.append("       AND b1.create_time <= ? ");

        sql.append(" ) t ")
            .append(" LEFT JOIN customers t1 ON t.客户编码=t1.customer_code ")
            .append(" LEFT JOIN pms_areagroup t2 ON t2.group_code=t.仓库编码 ")
            .append(" LEFT JOIN edi_goods_sku t3 ON (t3.sku_id=t.商品编码 AND t3.customer_code=t.客户编码)");
        sql.append(" GROUP BY t.客户编码, t.仓库编码, t.商品编码, t1.customer_name, t2.group_name, t3.sku_name");
        
        Query query = em.createNativeQuery(sql.toString());
        int i = 1;
        if (StringUtils.isNotBlank(warehouseCode)) query.setParameter(i++, warehouseCode);
        if (StringUtils.isNotBlank(customerCode))   query.setParameter(i++, customerCode);
        if (StringUtils.isNotBlank(sku))                   query.setParameter(i++, sku);
        if (StringUtils.isNotBlank(shopCode))         query.setParameter(i++, shopCode);
        if (StringUtils.isNotBlank(batchCode))        query.setParameter(i++, batchCode);
        if (StringUtils.isNotBlank(cancelStatus))      query.setParameter(i++, cancelStatus);
        if (StringUtils.isNotBlank(taskCode))          query.setParameter(i++, taskCode);
        if (StringUtils.isNotBlank(status)) {
            if ("countStock".equals(status)) {
                query.setParameter(i++, "1");
            } else {
                query.setParameter(i++, status);
            }
        }
        if (StringUtils.isNotBlank(fromDate))          query.setParameter(i++, fromDate);
        if (StringUtils.isNotBlank(toDate))              query.setParameter(i++, toDate);
        if (StringUtils.isNotBlank(sku))                   query.setParameter(i++, sku);
        if (StringUtils.isNotBlank(customerCode))   query.setParameter(i++, customerCode);
        if (StringUtils.isNotBlank(warehouseCode)) query.setParameter(i++, warehouseCode);
        if (StringUtils.isNotBlank(fromDate))          query.setParameter(i++, fromDate);
        if (StringUtils.isNotBlank(toDate))              query.setParameter(i++, toDate);
        
        
        return query.getResultList();
	}

    
    /**
     * 查找信息（新），重写
     * @param param 查询参数
     * @return 集合
     */
    @SuppressWarnings("unchecked")
    public List<Object[]> loadByParamNew(Map<String, Object> param) {
        String customerCode   = (String) param.get("customerCode");
        String warehouseCode = (String) param.get("warehouseCode");
        String sku                   = (String) param.get("sku");
        String shopCode         = (String) param.get("shopCode");
        String batchCode        = (String) param.get("batchCode");
        String cancelStatus      = (String) param.get("cancelStatus");
        String taskCode          = (String) param.get("taskCode");
        String fromDate          = (String) param.get("fromDate");
        String toDate              = (String) param.get("toDate");
        String status               = (String) param.get("status");
        
        
        //构建SQL
        StringBuffer sql = new StringBuffer("SELECT ");
        sql.append("   CAST(@i\\:=@i+1 AS CHAR) 序号, ")
            .append("   cus.customer_name 商家, ")
            .append("   eo.shopna 店铺, ")
            .append("   wh.group_name 仓库, ")
            .append("   o.batch_code 批次号, ")
            .append("   o.task_code 任务号, ")
            .append("   o.orderno 订单号, ")
            .append("   CASE eo.order_type ")
            .append("     WHEN 'multiple' THEN '多件' ")
            .append("     WHEN 'single' THEN '单件' ")
            .append("   ELSE CONCAT('未知类型:', eo.order_type) END 订单类型, ")
            .append("   e.sku_id SKU, ")
            .append("   sku.sku_name 商品名称, ")
            .append("   ifnull(o.express_no, o.ebill_no) 快递单号, ")
            .append("   o.customer_orderno 商家订单号, ")
            .append("   o.fromno 来源订单号, ")
            .append("   eo.addres 地址, ")
            .append("   e.qty 数量, ")
            .append("   e.pri 单价, ")
            .append("   CASE o.cancel_status ")
            .append("     WHEN 'cancel' THEN '取消单' ")
            .append("     WHEN 'refuse' THEN '拒收单' ")
            .append("     WHEN 'change' THEN '换货单' ")
            .append("     WHEN 'ok' THEN '正常单' ")
            .append("     WHEN 'outScope' THEN '超区件' ")
            .append("     WHEN 'lose' THEN '丢件单' ")
            .append("   ELSE CONCAT('未知状态:', o.cancel_status) END 订单状态, ")
            .append("   o.create_time 创建时间, ")
            .append("   o.status, e.nam, eo.shop_code, o.invoice_no, eo.invoice_title, o.customer_code, o.warehouse_code ")
            .append(" FROM work_order o ")
            .append("   LEFT JOIN edi_order eo ON eo.ordeno = o.orderno ")
            .append("   LEFT JOIN edi_order_item e ON e.ordeno = o.orderno ")
            .append("   LEFT JOIN customers cus ON cus.customer_code = e.customer_code ")
            .append("   LEFT JOIN pms_areagroup wh ON wh.group_code = o.warehouse_code ")
            .append("   LEFT JOIN edi_goods_sku sku ON (sku.customer_code = e.customer_code AND sku.sku_id = e.sku_id) ")
            .append("   , (select @i\\:=0) i ")
            .append(" WHERE 1=1 ");
        
        if (StringUtils.isNotBlank(warehouseCode)) sql.append("       AND o.warehouse_code= ? ");
        if (StringUtils.isNotBlank(customerCode))   sql.append("       AND o.customer_code= ? ");
        if (StringUtils.isNotBlank(sku))                   sql.append("       AND e.sku_id = ?  ");
        if (StringUtils.isNotBlank(shopCode))         sql.append("       AND eo.shop_code = ? ");
        if (StringUtils.isNotBlank(batchCode))        sql.append("       AND o.batch_code = ? ");
        if (StringUtils.isNotBlank(cancelStatus))      sql.append("       AND o.cancel_status = ? ");
        if (StringUtils.isNotBlank(taskCode))          sql.append("       AND o.task_code = ? ");
        if (StringUtils.isNotBlank(status)) {
            if ("countStock".equals(status)) {
                sql.append("       AND o.status > ? ");
            } else {
                sql.append("       AND o.status = ? ");
            }
        }
        if (StringUtils.isNotBlank(fromDate))          sql.append("       AND o.create_time >= ? ");
        if (StringUtils.isNotBlank(toDate))              sql.append("       AND o.create_time <= ? ");
        
        
        
        Query query = em.createNativeQuery(sql.toString());
        int i = 1;
        if (StringUtils.isNotBlank(warehouseCode)) query.setParameter(i++, warehouseCode);
        if (StringUtils.isNotBlank(customerCode))   query.setParameter(i++, customerCode);
        if (StringUtils.isNotBlank(sku))                   query.setParameter(i++, sku);
        if (StringUtils.isNotBlank(shopCode))         query.setParameter(i++, shopCode);
        if (StringUtils.isNotBlank(batchCode))        query.setParameter(i++, batchCode);
        if (StringUtils.isNotBlank(cancelStatus))      query.setParameter(i++, cancelStatus);
        if (StringUtils.isNotBlank(taskCode))          query.setParameter(i++, taskCode);
        if (StringUtils.isNotBlank(status)) {
            if ("countStock".equals(status)) {
                query.setParameter(i++, "1");
            } else {
                query.setParameter(i++, status);
            }
        }
        if (StringUtils.isNotBlank(fromDate))          query.setParameter(i++, fromDate);
        if (StringUtils.isNotBlank(toDate))              query.setParameter(i++, toDate);
        //add LiBin 20160808 方便打日志
        List<Object[]> results = query.getResultList();
        if(results.size()<1){
            logger.info("订单明细的查询SQL{}.", sql.toString());
        }
        
        return results;
    }

    /**
     * 查询出库信息列表
     * 
     * @param 
     * @return 
     * @throws 
     * @author <a href=mailto:libin@nryuncang.com>libin</a>
     * @version 1.0.0
     */
    public Pagination getPageOutstorageInfo(QueryOutstorageInfoVO oSInfo)  throws Exception{

        Pagination page = myBatisPage("outstorageInfoMapper.getOutstorageInfoCount","outstorageInfoMapper.getOutstorageInfoList", oSInfo);
        return page;
    }
}